//
//  MainController.m

#import "RootViewController.h"
#import "RootTableView.h"
#import "ApplicationDelegate.h"
#import "WordListViewController.h"

@implementation RootViewController

-(id) init
{
	if(self = [super init])
	{
//		self.title = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
		self.title = @"영어 단어 외우기";
	}
	
	return self;
}



-(void)viewWillAppear:(BOOL)animated
{
	NSLog(@"viewWillAppear of RootViewController");
}

-(void) loadView
{
	[super loadView];
	//윈도우 사이즈 얻어서 프레임에 맞추기
	//UIView* contentView = [[UIImageView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];
	
	//UIView에 이미지 로딩하기
	//[contentView setImage: [UIImage imageNamed: @"apple.jpg"]];
	
	//UITableView 붙이기
//	UITableView* contentView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

//	contentView.autoresizesSubviews = YES;
//	contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
	
//	contentView.backgroundColor = [UIColor whiteColor];
//	self.view = contentView;
//	[contentView release];

	// 네비케이션 색깔 바꾸기
	self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
	
	// 네비게이션 오른쪽에 버튼 추가하기 
	self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"오른쪽" style: UIBarButtonItemStylePlain target:self action: @selector(goRed)] autorelease];
	
	// 네비게이션 왼쪽에 버튼 추가하기 	
//	self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"왼쪽" style: UIBarButtonItemStylePlain target:self action: @selector(goBule)] autorelease];
}

#pragma mark UITableViewDataSource Methods

// Only one section in this table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{
	return 1;
}

// Return how many rows in the table
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
	return 5;
}

// Return a cell for the ith row
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	// Use re-usable cells to minimize the memory load
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"any-cell"];
	

	if (!cell) 
	{
		cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"any-cell"] autorelease];
	}
	
	// Set up the cell's text
	cell.text = [[UIFont familyNames] objectAtIndex:[indexPath row]];

	switch ([indexPath row]) 
	{
		case 2:
		{
			cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;			
			break;
		}
			
		default:
		{
			break;
		}
	}
	
	return cell;
}

#pragma mark UITableViewDelegateMethods

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath
{
//	printf("User selected row %d\n", [newIndexPath row] + 1);
	
	// Update the Navigation Item with the new font
//	NSString *fontName = [[UIFont familyNames] objectAtIndex:[newIndexPath row]];
//	CFShow([UIFont fontNamesForFamilyName:fontName]);
//	[(UILabel *)self.navigationItem.titleView setFont:[UIFont fontWithName: fontName size:[UIFont systemFontSize]]];
	
	
	switch ([newIndexPath row]) 
	{
		case 0:
		{
			AppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];
			wordListViewcontroller = [[WordListViewController alloc] init];
			[appDelegate.navigationController pushViewController:wordListViewcontroller animated:YES];
		}
		break;
			
		default:
		{
			
		}
		break;
	}
}


-(void) goRed
{
	self.view.backgroundColor = [UIColor colorWithRed:1.0f green:0.45f blue:0.45f alpha:1.0f];
}

-(void) goBule
{
	self.view.backgroundColor = [UIColor colorWithRed:0.45f	green:0.45f blue:1.0f alpha:1.0f];
}

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
	return YES;
}

-(void) didReceiveMemoryWarning
{
	[super didReceiveMemoryWarning];
}

-(void) dealloc
{
	[wordListViewcontroller release];
	[super dealloc];
}

@end
